import Vue from "vue";
import VueI18n from "vue-i18n";
import { localRead } from "@/libs/util";

Vue.use(VueI18n);
// 自动根据浏览器系统语言设置语言
const navLang = navigator.language;
const localLang = navLang === "zh-CN" || navLang === "en-US" ? navLang : false;
let lang = localRead("lang") || localLang || "zh-CN"; //保持语言
Vue.config.lang = lang;

// vue-i18n 6.x+写法
Vue.locale = () => {};

let messages = {};
// 中文
import customZhCn from "./lang/zh-CN";
import iviewZhCn from "iview/dist/locale/zh-CN";
import eleZhCn from "element-ui/lib/locale/lang/zh-CN";
import VxeTableZhCn from "vxe-table/lib/locale/lang/zh-CN";
messages["zh-CN"] = Object.assign(customZhCn, iviewZhCn, eleZhCn, VxeTableZhCn);

// 繁体中文
import customZhTw from "./lang/zh-TW";
import iviewZhTw from "iview/dist/locale/zh-TW";
import eleZhTw from "element-ui/lib/locale/lang/zh-TW";
import VxeTableZhTw from "vxe-table/lib/locale/lang/zh-TW";
messages["zh-TW"] = Object.assign(customZhTw, iviewZhTw, eleZhTw, VxeTableZhTw);

// 英文
import customEnUs from "./lang/en-US";
import iviewEnUs from "iview/dist/locale/en-US";
import eleEnUs from "element-ui/lib/locale/lang/en";
import VxeTableEnUs from "vxe-table/lib/locale/lang/en-US";
messages["en-US"] = Object.assign(customEnUs, iviewEnUs, eleEnUs, VxeTableEnUs);
// 日语
import customJaJp from "./lang/ja-JP";
import iviewJaJp from "iview/dist/locale/ja-JP";
import eleJaJp from "element-ui/lib/locale/lang/ja";
import VxeTableJaJp from "vxe-table/lib/locale/lang/ja-JP";
messages["ja-JP"] = Object.assign(customJaJp, iviewJaJp, eleJaJp, VxeTableJaJp);

// 韩语
import customKoKr from "./lang/ko-KR";
import iviewKoKr from "iview/dist/locale/ko-KR";
import eleKoKr from "element-ui/lib/locale/lang/ko";
import VxeTableKoKr from "vxe-table/lib/locale/lang/ko-KR";
messages["ko-KR"] = Object.assign(customKoKr, iviewKoKr, eleKoKr, VxeTableKoKr);

const i18n = new VueI18n({
    locale: lang,
    messages,
    silentTranslationWarn: true, // 取消警告
});

export default i18n;
